
/* -*- C++ -*- */

//=============================================================================
/*
* @author Feloweria <380374483@qq.com>
* Copyright (C) Feloweria
*
* $ID 2014-07-03 15:04:05 AM
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
* @version 1.0
*/
//=============================================================================

FELOWRIA_BEGIN

inline DataOutputStream::DataOutputStream(char *data,char *data_end)
:data(data),data_end(data_end)
{

}

inline DataOutputStream::~DataOutputStream()
{

}

inline int32 DataOutputStream::Readable() const
{
	return data_end - data;
}
inline void DataOutputStream::Readable(char *&rdPtr, int32 &size)
{
	rdPtr = data;
	size = data_end - data;
}

inline bool DataOutputStream::Read(char *bytes, uint32 size)
{
	if(!ReadPeek(bytes,size))
		return false;

	data += size;
	return true;
}

inline bool DataOutputStream::ReadPeek(char *bytes, uint32 size)
{
	if(!bytes || !size || data + size > data_end)
		return false;

	memcpy(bytes, data, size);
	return true;
}

inline bool DataOutputStream::ReadSkip(uint32 size)
{
	if(data + size > data_end)
		return false;

	data += size;
	return true;
}

inline int32 DataOutputStream::ReadSize() const
{
	return Readable();
}

FELOWRIA_END